package com.xhu.collegestudentrentalsystem.module.user.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xhu.collegestudentrentalsystem.module.user.entity.Feedback;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author zhu huilin
 * @date 2023/3/29 13:33
 */
public interface FeedbackDAO extends BaseMapper<Feedback> {
    /**
     * 根据房东的id查询所有该房东发布房屋的用户反馈信息
     */
    @Select("SELECT feedback.* FROM feedback,house_order WHERE house_order.id = feedback.order_id AND owner_user_id = #{userId} " +
            " order by status, create_time desc")
    public List<Feedback> findFeedbackByOwnerId(Long userId);

    /**
     * 查询数据条数
     */
    @Select("SELECT COUNT(*) FROM feedback,house_order WHERE house_order.id = feedback.order_id AND owner_user_id = #{userId}")
    public Integer findFeedbackCountByOwnerId(Long userId);

    /**
     * 根据id更改反馈表中的回复和状态
     */
    @Update("update feedback set reply=#{reply}, status = #{status} where id = #{id}")
    public Integer updateReplyAndStatusById(@Param("id") Long feedbackId, @Param("reply")String reply, @Param("status")Integer status);
}